package com.lpit.config;

import io.searchbox.client.JestClient;
import io.searchbox.client.JestClientFactory;
import io.searchbox.client.config.HttpClientConfig;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;

@Data
@Configuration
@PropertySource("classpath:config/elasticsearch.properties")//地址
@ConfigurationProperties(prefix = "spring.elasticsearch.jest")
//@ComponentScan(basePackages = "com.lpit.search.service")
public class ElasticsearchConfig {

    private String url;
    private Integer readTime;
    private Integer connectionTime;

    @Bean
    public JestClient jestClient(){
        JestClientFactory jestClientFactory = new JestClientFactory();
        jestClientFactory.setHttpClientConfig(new HttpClientConfig
                .Builder(this.url)
                .multiThreaded(true)
                .connTimeout(this.connectionTime)
                .readTimeout(this.readTime)
                .build());
        return jestClientFactory.getObject();
    }

}
